/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LoginAZTech.java
 *
 * Created on 07/12/2009, 16:20:25
 */
package sigbar.view;

import sigbar.access.BDInterface;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Denis
 */
public class LoginSigBar extends javax.swing.JFrame {

    BDInterface bcon;

    /** Creates new form LoginSigBar */
    public LoginSigBar() {

        initComponents();
        centralizarTela();
        jLabel6.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        jLabel7.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        //;
        bcon = new BDInterface();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(330, 350));
        setResizable(false);
        setUndecorated(true);
        getContentPane().setLayout(null);

        jLabel1.setText("Login:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(10, 210, 38, 17);

        jLabel2.setText("Senha:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(10, 260, 45, 17);

        jTextField1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField1KeyPressed(evt);
            }
        });
        getContentPane().add(jTextField1);
        jTextField1.setBounds(50, 200, 260, 40);

        jPasswordField1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jPasswordField1.setText("senha");
        jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jPasswordField1KeyPressed(evt);
            }
        });
        getContentPane().add(jPasswordField1);
        jPasswordField1.setBounds(50, 250, 260, 40);

        jLabel3.setFont(new java.awt.Font("Tahoma", 3, 36));
        jLabel3.setText("AZTech SigBar");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(20, 80, 270, 80);

        jPanel1.setMaximumSize(new java.awt.Dimension(311, 49));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel6.setIcon(new javax.swing.ImageIcon("/home/hdhzero/NetBeansProjects/trunk/SIGBAR/src/sigbar/resourcesemoticon_smile.png")); // NOI18N
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel6MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel6MouseExited(evt);
            }
        });
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, -1, -1));

        jLabel4.setIcon(new javax.swing.ImageIcon("/home/hdhzero/NetBeansProjects/trunk/SIGBAR/src/sigbar/resourcesleftLogin.png")); // NOI18N
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(216, 0, 50, -1));

        jLabel7.setIcon(new javax.swing.ImageIcon("/home/hdhzero/NetBeansProjects/trunk/SIGBAR/src/sigbar/resourcescross.png")); // NOI18N
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel7MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel7MouseExited(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel7MouseReleased(evt);
            }
        });
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 10, -1, -1));

        jLabel5.setIcon(new javax.swing.ImageIcon("/home/hdhzero/NetBeansProjects/trunk/SIGBAR/src/sigbar/resourcesrightLogin.png")); // NOI18N
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 0, 50, -1));
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 200, -1));

        jLabel9.setIcon(new javax.swing.ImageIcon("/home/hdhzero/NetBeansProjects/trunk/SIGBAR/src/sigbar/resourcesmeioLogin.png")); // NOI18N
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(265, 0, 5, -1));

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 320, 10);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if (verificaCampos()) {

                int opc = 1;//bcon.login(jTextField1.getText(), jPasswordField1.getPassword().toString());
                if (opc == 0) {
                    JOptionPane.showMessageDialog(null, "Senha e/ou login inválidos");
                } else {
                    this.setVisible(false);
                    MainForm janela = new MainForm(bcon, opc);

                    janela.setVisible(true);
                }
            //JOptionPane.showMessageDialog(null, "Campos a!");
            } else {
                JOptionPane.showMessageDialog(null, "Campos faltando!");
            }
        }
    }//GEN-LAST:event_jTextField1KeyPressed

    private void jPasswordField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordField1KeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if (verificaCampos()) {
                String pass = String.copyValueOf(jPasswordField1.getPassword());
                JOptionPane.showMessageDialog(null, pass);
                int opc = bcon.login(jTextField1.getText(), pass);
                if (opc == 0) {
                    JOptionPane.showMessageDialog(null, "Senha e/ou login inválidos");
                } else {
                    this.setVisible(false);
                    MainForm janela = new MainForm(bcon, opc);

                    janela.setVisible(true);
                }
            //JOptionPane.showMessageDialog(null, "Campos a!");
            } else {
                JOptionPane.showMessageDialog(null, "Campos faltando!");
            }
        }
    }//GEN-LAST:event_jPasswordField1KeyPressed

    private void jLabel7MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseEntered
        jLabel8.setText("Sair do sistema");
    //setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jLabel7MouseEntered

    private void jLabel6MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel6MouseEntered
        jLabel8.setText("");
    }//GEN-LAST:event_jLabel6MouseEntered

    private void jLabel6MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel6MouseExited
        jLabel8.setText("");
    //setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR))
    }//GEN-LAST:event_jLabel6MouseExited

    private void jLabel7MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseExited
        jLabel8.setText("");
    }//GEN-LAST:event_jLabel7MouseExited

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel7MouseClicked

    private void jLabel7MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseReleased
        System.exit(0);
    }//GEN-LAST:event_jLabel7MouseReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new LoginSigBar().setVisible(true);
            }
        });
    }

    private boolean verificaCampos() {
        boolean error = true;
        if (jTextField1.getText().isEmpty()) {
            error = false;
        }
        if (jPasswordField1.getPassword().toString().isEmpty()) {
            error = false;
        }
        if (error) {
            return true;
        }
        return false;
    }

    public void centralizarTela() {
        Dimension tela = Toolkit.getDefaultToolkit().getScreenSize();

        setSize(330, 350); //ponha aqui suas medidas
        setLocation((tela.width - this.getSize().width) / 2,
                (tela.height - this.getSize().height) / 2);
    }

    public void verificarLogin(int opc) {
        switch (opc) {
            case 0:

                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                break;
            case 6:
                break;
            case 7:
                break;

        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
